package com.ruoyi.performance.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Random;

import com.ruoyi.performance.domain.ro.GetListRo;
import com.ruoyi.performance.domain.vo.ContractNameVo;
import com.ruoyi.performance.domain.vo.DanHaoVo;
import com.ruoyi.rest.domain.vo.TreeNameVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.performance.mapper.SillPerformanceMapper;
import com.ruoyi.performance.domain.SillPerformance;
import com.ruoyi.performance.service.ISillPerformanceService;

/**
 * 员工绩效表Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-08-12
 */
@Service
public class SillPerformanceServiceImpl implements ISillPerformanceService 
{
    @Autowired
    private SillPerformanceMapper sillPerformanceMapper;

    /**
     * 查询员工绩效表
     * 
     * @param id 员工绩效表主键
     * @return 员工绩效表
     */
    @Override
    public SillPerformance selectSillPerformanceById(Long id)
    {
        return sillPerformanceMapper.selectSillPerformanceById(id);
    }

    /**
     * 查询员工绩效表列表
     * 
     * @param sillPerformance 员工绩效表
     * @return 员工绩效表
     */
    @Override
    public List<SillPerformance> selectSillPerformanceList(SillPerformance sillPerformance)
    {
        return sillPerformanceMapper.selectSillPerformanceList(sillPerformance);
    }

    @Override
    public List<SillPerformance> selectSillPerformanceList(GetListRo getListRo) {
        return sillPerformanceMapper.selectQueryList(getListRo);
    }

    /**
     * 新增员工绩效表
     * 
     * @param sillPerformance 员工绩效表
     * @return 结果
     */
    @Override
    public int insertSillPerformance(SillPerformance sillPerformance)
    {
        extracted(sillPerformance);

        extracted1(sillPerformance);
        return sillPerformanceMapper.insertSillPerformance(sillPerformance);
    }

    //生成合同单号
    private static void extracted1(SillPerformance sillPerformance) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmm");
        String date = dateFormat.format(new Date());
        Random random = new Random();
        int randomNum = 1000 + random.nextInt(9000);
        sillPerformance.setSillPerformanceContract(date+randomNum);
    }

    //截取年月
    private static void extracted(SillPerformance sillPerformance) {
        Date sillPerformanceTime = sillPerformance.getSillPerformanceTime();
        //得到日期中的日
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        // 使用ISO_LOCAL_DATE_TIME格式解析日期时间
        String dateTimeString = dateFormat.format(sillPerformanceTime);
        // 将转换为的字符串进行拆分
        String[] split = dateTimeString.split("-");
        // 输出年月日
        sillPerformance.setSillPerformanceDate(split[0]+"年"+split[1]+"月");
    }

    /**
     * 修改员工绩效表
     * 
     * @param sillPerformance 员工绩效表
     * @return 结果
     */
    @Override
    public int updateSillPerformance(SillPerformance sillPerformance)
    {
        extracted(sillPerformance);
        return sillPerformanceMapper.updateSillPerformance(sillPerformance);
    }

    /**
     * 批量删除员工绩效表
     * 
     * @param ids 需要删除的员工绩效表主键
     * @return 结果
     */
    @Override
    public int deleteSillPerformanceByIds(Long[] ids)
    {
        return sillPerformanceMapper.deleteSillPerformanceByIds(ids);
    }

    /**
     * 删除员工绩效表信息
     * 
     * @param id 员工绩效表主键
     * @return 结果
     */
    @Override
    public int deleteSillPerformanceById(Long id)
    {
        return sillPerformanceMapper.deleteSillPerformanceById(id);
    }

    @Override
    public List<DanHaoVo> getDanHao() {

        List<DanHaoVo> allFloor = sillPerformanceMapper.getDanHao();
        return allFloor;
    }

    @Override
    public List<ContractNameVo> getContractName(String sillPerformanceContract) {
        List<ContractNameVo> allFloor = sillPerformanceMapper.getContractName(sillPerformanceContract);
        return allFloor;

    }
}
